import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class PaperTypeCounter implements Visitor {
    private final Map<PaperType, Integer> typeCounts = new HashMap<>();

    @Override
    public void visit(Paper paper, Student student) {
        PaperType type;
        if (paper instanceof Thesis) {
            type = PaperType.Thesis;
        } else if (paper instanceof ConferencePaper) {
            type = PaperType.ConferencePaper;
        } else if (paper instanceof JournalPaper) {
            type = PaperType.JournalPaper;
        } else {
            type = PaperType.Any;
        }
        
        typeCounts.put(type, typeCounts.getOrDefault(type, 0) + 1);
    }

    @Override
    public Map<PaperType, Integer> getResult() {
        return Collections.unmodifiableMap(typeCounts);
    }
}    